package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.EducationalBackgroundTypeMapper;
import com.wanmait.recruit.pojo.EducationalBackgroundType;
import com.wanmait.recruit.pojo.Resume;
import com.wanmait.recruit.service.EducationExpService;
import com.wanmait.recruit.service.EducationalBackgroundTypeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.wanmait.recruit.pojo.EducationExp;
import com.wanmait.recruit.mapper.EducationExpMapper;
import org.springframework.transaction.annotation.Transactional;

@Service("educationExpService")
@Transactional(rollbackFor = Exception.class)
public class EducationExpServiceImpl implements EducationExpService {

    @Resource
    private EducationExpMapper educationExpMapper;
    @Resource
    private EducationalBackgroundTypeService educationalBackgroundTypeService;

    public int deleteByPrimaryKey(Integer id){
        return educationExpMapper.deleteByPrimaryKey(id);
    }

    public void insert(EducationExp record){

        educationExpMapper.insertSelective(record);
    }

    @Override
    public void delete(EducationExp object) {

    }

    @Override
    public void update(EducationExp object) {

    }

    @Override
    public PageInfo<EducationExp> search(int pageNum, int pageSize) {
        return null;
    }

    public int insertSelective(EducationExp record){
        return educationExpMapper.insertSelective(record);
    }

    public EducationExp selectByPrimaryKey(Integer id){
        return educationExpMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(EducationExp record){
        return educationExpMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(EducationExp record){
        return educationExpMapper.updateByPrimaryKey(record);
    }

   
    @Override
    public String findEducation(Integer resumeId) {
        ArrayList<EducationExp> educationExp = educationExpMapper.findEducationalExperience(resumeId);
        ArrayList x=new ArrayList();
        for (EducationExp educationExp1:educationExp){
            x.add(educationExp1.getEducationalBackgroundType().getId());
        }
        int y= (int) Collections.max(x);//学历id
        return educationalBackgroundTypeService.selectByEducationTypeId(y);

    }

    @Override
    public boolean findIsEducation(Integer resumeId) {
        ArrayList<EducationExp> educationExp = educationExpMapper.findEducationalExperience(resumeId);
        if (educationExp.size()!=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void updateEducation(Integer personId, Integer educationtypeId) {
        educationExpMapper.updateEducation(personId,educationtypeId);
    }

    @Override
    public void insertEducation(Integer personId, Integer educationtypeId) {
        educationExpMapper.insertEducation(personId,educationtypeId);
    }

    @Override
    public void delEducation(Integer id) {
        Integer educationtypeId=1;
        educationExpMapper.updateEducation(id,educationtypeId);
    }

    @Override
    public boolean findIsEducationalExperience(Integer resumeId) {
        ArrayList<EducationExp> educationExp = educationExpMapper.findEducationalExperience(resumeId);
        if (educationExp.size()!=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public ArrayList<EducationExp> findEducationalExperience(Integer resumeId) {
        return educationExpMapper.findEducationalExperience(resumeId);
    }

    @Override
    public void delEducationExp(Integer id) {
        educationExpMapper.updateEducationExpDel(id);
    }

    @Override
    public EducationExp findByResume(Resume resume) {
        return educationExpMapper.findByResumeId(resume.getId());
    }
}
